<?php
include_once("../config.php");
$code=$_GET['code'];
$grant_type='authorization_code';
$url='https://api.weixin.qq.com/sns/jscode2session';
$url= sprintf("%s?appid=%s&secret=%s&js_code=%s&grant_type=%s",$url,$appid,$secretkey,$code,$grant_type);
$fp=file_get_contents($url);
$user_data=json_decode($fp);
$uid=$user_data->openid;
$t=time();
if($uid==''||empty($uid)){
	die('{"status":0,"msg":"禁止登录","zt":9999,"openid":"'.$t.'"}');
}
$sql = "select value from config where name='appname'";
$requ=mysqli_query($con,$sql);
$rs = mysqli_fetch_array($requ);
$appname = $rs['value'];
$sql = "select value from config where name='isreg'";
$requ=mysqli_query($con,$sql);
$rs = mysqli_fetch_array($requ);
$isreg = $rs['value'];
$sql = "select value from config where name='waittime'";
$requ=mysqli_query($con,$sql);
$rs = mysqli_fetch_array($requ);
$waittime = $rs['value'];
$config = '{"appname":"'.$appname.'","isreg":"'.$isreg.'","waittime":"'.$waittime.'"}';


$sql="select juese,status from user where openid='$uid'";
$requ=mysqli_query($con,$sql);
if(mysqli_num_rows($requ)){
	$rs=mysqli_fetch_array($requ);
	if($rs['status']==1){
		die('{"status":1,"msg":"登录成功","zt":'.$rs['juese'].',"openid":"'.$uid.'","config":'.$config.'}');
	}else{
		die('{"status":0,"msg":"禁止登录","zt":9999,"openid":"'.$t.'"}');
	}
}else{
	die('{"status":1,"msg":"未注册","zt":0,"openid":"'.$uid.'","config":'.$config.'}');
}
?>